<?php

namespace App\Exceptions;

use App\Kuafu\Base\Enum\BaseCodeEnum;
use App\Kuafu\Base\Service\BaseService;
use Throwable;

class BaseException extends \Exception
{
    /**
     * 状态码
     * @var mixed
     */
    public         $code   = BaseCodeEnum::ERR_SERVER_ERROR;
    private static $module = 'Base';

    /**
     * 错误具体信息
     * @var string
     */
    public $message = BaseCodeEnum::CODE_TEXT[BaseCodeEnum::ERR_SERVER_ERROR];

    public function __construct($code = 0, $message = "", Throwable $previous = null)
    {
        self::setModule(BaseService::getModuleByNameSpace(static::class));
        if (empty($message)) {
            $message = BaseCodeEnum::getCodeTextAutoClass($code);
        }
        parent::__construct($message, $code, $previous);
    }

    public static function setModule(string $module)
    {
        static::$module = $module;
    }

    public static function getModule()
    {
        return static::$module;
    }
}
